<?php
/*
  [EWEISHOP] Copyright(C) 2017 Elinkint Inc.
  This is NOT a freeware, use is subject to license terms
   
  OfficialAccountQrCode.php 2018-05-25 11:41 likexin
   
*/

namespace common\library\wechat\officialaccount;

use common\library\wechat\WechatApi;
use common\component\wechat\Wechat;

class OfficialAccountQrCode extends WechatApi
{

    /**
     * 创建临时二维码
     * @param string|integer $sceneValue 场景值
     * @param int|null $expireSeconds 失效时间(秒) 最长30天(2592000秒)
     * @return mixed [ticket, expire_seconds, url]
     * @link https://www.easywechat.com/docs/master/zh-CN/basic-services/qrcode
     * @link https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1443433542
     */
    public static function temporary($sceneValue, int $expireSeconds = null)
    {
        $result = self::getInstance()->qrcode->temporary($sceneValue, $expireSeconds);
        return Wechat::apiError($result);
    }

    /**
     * 创建永久二维码
     * @param string|integer $sceneValue 场景值
     * @return mixed [ticket, url]
     * @link https://www.easywechat.com/docs/master/zh-CN/basic-services/qrcode
     * @link https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1443433542
     */
    public static function forever($sceneValue)
    {
        $result = self::getInstance()->qrcode->forever($sceneValue);
        return Wechat::apiError($result);
    }

    /**
     * 获取二维码地址
     * @param string $ticket 二维码TICKET
     * @return mixed https://api.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET
     * @link https://www.easywechat.com/docs/master/zh-CN/basic-services/qrcode
     * @link https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1443433542
     */
    public static function url(string $ticket)
    {
        $result = self::getInstance()->qrcode->url($ticket);
        return Wechat::apiError($result);
    }

}